import request from 'umi-request';
import { useState, useEffect } from 'react';

const useWeather = () => {
  const [wtNm, setWtNm] = useState<string>('');
  const [wtTemp, setWtTemp] = useState<string>('');

  useEffect(() => {
    request
      .get(
        'http://api.k780.com/?app=weather.realtime&weaId=94&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json',
      )
      .then((response) => {
        if (response.success === '1') {
          setWtNm(response.result?.realTime?.wtNm);
          setWtTemp(response.result?.realTime?.wtTemp);
        }
      });
  }, []);

  return [wtNm, wtTemp];
};

export default useWeather;
